Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
Use .replace() with "

I am currently working on getting data from an API, and I want to remove some characters from what it returns.

What I get back is {"usd":323.67}, but the currency and price may change depending on the input.

I want to remove the {}, usd (or other currency), "" and :. I searched, and found .replace() could be a good solution, if you replace the character with nothing. But when I use .replace(""", "");, I of course get an error. When I do, .replace("{}", "");, it doesn't replace the {} with nothing either. And because I use a constant for the currency, because the user can choose, the currency it not always the same, so I thought it could use .replace(${currency}`, ""), but that also doesn't work.

What should I do to remove these things from my string?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As others commented, parse your data as JSON and then get the value using your currency variable, something like this (not sure about what framework you are using, so the currency replacement may vary from what's shown here):

data = {"usd":323.67};
value = data.${currency};
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to find all numbers in string and then concat them with '.' symbol

const getValue = (str) => str.match(/\d+/g).join('.')
console.log(getValue('{"usd":323.67}'))
console.log(getValue('{"rub":323,67p}'))
console.log(getValue('"euro":333-00'))

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda